// var i;
// var c = cc._decorator;
// var s = c.ccclass;
// var l = c.property;
// var u = (function (e) {
//     function t() {
//         var t = (null !== e && e.apply(this, arguments)) || this;
//         t.label = null;
//         t.text = "hello";
//         t.offtime = 0;
//         return t;
//     }
//     __extends(t, e);
//     t.prototype.start = function () {};
//     t.prototype.getImageMemory = function () {
//         var e = cc.assetManager.assets;
//         var t = [];
//         e.forEach(function (e) {
//             if (e instanceof cc.SpriteFrame) {
//                 t.push(e);
//             }
//         });
//         t.sort(function (e, t) {
//             return t.getTexture().height * t.getTexture().width - e.getTexture().height * e.getTexture().width;
//         });
//         var o = "";
//         var n = 0;
//         t.forEach(function (e) {
//             var t = e.getTexture();
//             var i = e.getOriginalSize();
//             var a = t._native;
//             var r = t._uuid;
//             var c = (((i.width * i.height * (a.indexOf("jpg") > 0 ? 3 : 4)) / 1024 / 1024) * 1e4) / 1e4;
//             n += c;
//             o = o + "\n" + r + a + "...." + c + "M";
//             console.log("内存占用:", r + a + e.name + "\n占用内存:" + c.toFixed(2) + "M");
//         });
//         n = Math.floor(1e4 * n) / 1e4;
//         o = "Total Image Mem...." + n + "M" + o;
//         console.log("Image Mem==", o);
//         console.log("共占用内存:" + n.toFixed(2) + "M");
//         return n.toFixed(2);
//     };
//     t.prototype.updateMonegy = function () {};
//     t.prototype.update = function () {};
//     __decorate([l(cc.Label)], t.prototype, "label", void 0);
//     __decorate([l], t.prototype, "text", void 0);
//     return __decorate([s], t);
// })(cc.Component);
// exports.default = u;
const { ccclass, property } = cc._decorator;

/**
 * 建议类名: ImageMemoryManager
 */
@ccclass
export default class lookMemery extends cc.Component {
    /** 标签组件 */
    @property(cc.Label)
    public label: cc.Label | null = null;

    /** 文本内容 */
    @property
    public text: string = "hello";

    /** 关闭时间 */
    public offtime: number = 0;

    /**
     * 生命周期方法，组件启动时调用
     * 建议方法名: onStart
     */
    start() { }

    /**
     * 获取图片内存占用情况
     * @returns {string} 内存占用情况
     * 建议方法名: calculateImageMemoryUsage
     */
    calculateImageMemoryUsage(): string {
        const allAssets = cc.assetManager.assets;
        const spriteFramesList: cc.SpriteFrame[] = [];

        // 筛选出所有的SpriteFrame资产
        allAssets.forEach((singleAsset) => {
            if (singleAsset instanceof cc.SpriteFrame) {
                spriteFramesList.push(singleAsset);
            }
        });

        // 按照宽高倒序排序
        spriteFramesList.sort((frameA, frameB) => {
            return frameB.getTexture().height * frameB.getTexture().width - frameA.getTexture().height * frameA.getTexture().width;
        });

        let memoryUsageDetails = "";
        let totalMemoryUsage = 0;

        // 计算每个SpriteFrame的内存占用
        spriteFramesList.forEach((spriteFrame) => {
            const texture = spriteFrame.getTexture();
            const originalSize = spriteFrame.getOriginalSize();
            const nativeUrl = texture["_native"];
            const uuid = texture["_uuid"];
            const bytesPerPixel = nativeUrl.includes("jpg") ? 3 : 4;
            const memoryUsage = (originalSize.width * originalSize.height * bytesPerPixel / 1024 / 1024);
            totalMemoryUsage += memoryUsage;
            memoryUsageDetails += `\n${uuid}${nativeUrl}....${memoryUsage.toFixed(2)}M`;
            console.log("内存占用:", `${uuid}${nativeUrl}${spriteFrame.name}\n占用内存:${memoryUsage.toFixed(2)}M`);
        });

        totalMemoryUsage = Math.floor(totalMemoryUsage * 1e4) / 1e4;
        memoryUsageDetails = `Total Image Mem....${totalMemoryUsage.toFixed(2)}M${memoryUsageDetails}`;
        console.log("Image Mem==", memoryUsageDetails);
        console.log("共占用内存:", `${totalMemoryUsage.toFixed(2)}M`);

        return totalMemoryUsage.toFixed(2);
    }

    /**
     * 更新金钱信息
     * 建议方法名: updateMoneyInfo
     */
    updateMoneyInfo() { }

    /**
     * 生命周期方法，每帧调用
     * 建议方法名: onUpdate
     */
    update(deltaTime: number) { }
}